<?php

/**
 * @Author: Thans
 * @Date:   2018-09-19 22:38:53
 * @Last Modified by:   Thans
 * @Last Modified time: 2018-09-20 00:07:18
 */

namespace app\admin\controller;

use app\admin\facade\UploadGroup;
use app\common\controller\Admin;
use think\facade\Request;

class UploadGroupController extends Admin
{
    //获取全部分组
    public function index()
    {
        $data['type'] = Request::has('type') ? Request::get('type') : 'image';
        $data['keyword'] = Request::get('keyword');
        $list = UploadGroup::getList($data);
        $this->results($list);
    }

    public function read($id)
    {
        if (empty($id)) {
            $this->result('', 4001, '参数错误', 'json');
        }
        $res = UploadGroup::index($id);
        $this->results($res);
    }

    public function save()
    {
        $data['type'] = Request::param('type') ? Request::param('type') : 'image';
        $data['list_order'] = Request::has('list_order') ? Request::param('list_order') : '1000';
        $data['name'] = Request::post('name');
        $res = UploadGroup::save($data);
        $this->results($res);
    }

    public function delete($id)
    {
        if (empty($id)) {
            $this->result('', 4001, '参数错误', 'json');
        }
        $res = UploadGroup::delete($id);
        $this->results($res);
    }

    public function update($id)
    {
        if (empty($id) || empty(Request::param('name'))) {
            $this->result('', 4001, '参数错误', 'json');
        }
        $data['name'] = Request::param('name');
        $res = UploadGroup::update($id, $data);
        $this->results($res);
    }
}
